/** <a href="http://www.cpupk.com/decompiler">Eclipse Class Decompiler</a> plugin, Copyright (c) 2017 Chen Chao. **/
package com.minierp.view;

import com.minierp.bean.StafferBean;
import java.util.List;
import java.util.Map;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.usermodel.HSSFRichTextString;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.springframework.web.servlet.view.document.AbstractExcelView;

public class InnerPbListExcelView extends AbstractExcelView {
	public void buildExcelDocument(Map model, HSSFWorkbook workbook,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		response.reset();
		response.setContentType("APPLICATION/vnd.ms-excel");
		response.setHeader("Content-Disposition",
				"attachment;filename=\"InnerPbList.xls\"");
		HSSFFont font = workbook.createFont();
		font.setFontHeightInPoints(10);
		font.setColor(10);
		font.setFontName("黑体");
		font.setBoldweight(700);
		HSSFCellStyle cellStyle = workbook.createCellStyle();
		cellStyle.setFont(font);
		cellStyle.setAlignment(2);
		cellStyle.setBorderBottom(1);
		cellStyle.setWrapText(true);
		cellStyle.setFillForegroundColor(22);
		cellStyle.setFillPattern(1);
		HSSFSheet sheet = workbook.createSheet("list");
		HSSFRow r = sheet.createRow(0);
		r.createCell(0).setCellValue(new HSSFRichTextString("部门"));
		r.createCell(1).setCellValue(new HSSFRichTextString("姓名"));
		r.createCell(2).setCellValue(new HSSFRichTextString("职位"));
		r.createCell(3).setCellValue(new HSSFRichTextString("手机"));
		r.createCell(4).setCellValue(new HSSFRichTextString("移动短号"));
		r.createCell(5).setCellValue(new HSSFRichTextString("QQ"));
		r.createCell(6).setCellValue(new HSSFRichTextString("邮箱"));
		r.createCell(7).setCellValue(new HSSFRichTextString("电话"));
		r.createCell(8).setCellValue(new HSSFRichTextString("分机"));
		List list = (List) model.get("stafferList");

		for (int os = 0; os < list.size(); ++os) {
			StafferBean bean = (StafferBean) list.get(os);
			String possie = "";
			String mobile = "";
			String subMobile = "";
			String qq = "";
			String email = "";
			String phone = "";
			String subPhone = "";
			if (bean.getStaffer().getPossie() != null) {
				possie = bean.getStaffer().getPossie();
			}

			if (bean.getStaffer().getMobile() != null) {
				mobile = bean.getStaffer().getMobile();
			}

			if (bean.getStaffer().getSubMobile() != null) {
				subMobile = bean.getStaffer().getSubMobile();
			}

			if (bean.getStaffer().getQq() != null) {
				qq = bean.getStaffer().getQq();
			}

			if (bean.getStaffer().getEmail() != null) {
				email = bean.getStaffer().getEmail();
			}

			if (bean.getStaffer().getPhone() != null) {
				phone = bean.getStaffer().getPhone();
			}

			if (bean.getStaffer().getSubPhone() != null) {
				subPhone = bean.getStaffer().getSubPhone();
			}

			r = sheet.createRow(os + 1);
			r.createCell(0).setCellValue(
					new HSSFRichTextString(bean.getDepName()));
			r.createCell(1).setCellValue(
					new HSSFRichTextString(bean.getStaffer().getStafferName()));
			r.createCell(2).setCellValue(new HSSFRichTextString(possie));
			r.createCell(3).setCellValue(new HSSFRichTextString(mobile));
			r.createCell(4).setCellValue(new HSSFRichTextString(subMobile));
			r.createCell(5).setCellValue(new HSSFRichTextString(qq));
			r.createCell(6).setCellValue(new HSSFRichTextString(email));
			r.createCell(7).setCellValue(new HSSFRichTextString(phone));
			r.createCell(8).setCellValue(new HSSFRichTextString(subPhone));
		}

		ServletOutputStream arg18 = response.getOutputStream();
		workbook.write(arg18);
		arg18.flush();
		arg18.close();
	}
}